<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>宿舍管理系统</title>
    <link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/admin/css/login.css"/>
    <script src="/static/admin/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<div class="m-login-bg">
    <div class="m-login">
        <h3>宿舍管理系统</h3>
        <div style="border-radius: 15px;padding: 25px 25px 5px 25px;background: url('/static/admin/images/login/login_smallBg.png');">
            <form class="layui-form">
                <div class="layui-form-item"
                     style="background: url('/static/admin/images/login/login_text.png');background-size: 100% 100%;">
                    <img alt="" src="/static/admin/images/login/login_phone.png"
                         style="float: left;margin-top: 3%;margin-left: 5%;">
                    <input type="text"
                           style="width: 85%;border-style: none none solid none;background-color: transparent;margin-left: 15%;"
                           name="username" id="username" required lay-verify="required" placeholder="请输入用户名"
                            autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item"
                     style="background: url('/static/admin/images/login/login_text.png');background-size: 100% 100%;">
                    <img alt="" src="/static/admin/images/login/login_password.png"
                         style="float: left;margin-top: 3%;margin-left: 5%;">
                    <input type="password"
                           style="width: 85%;border-style: none none solid none;background-color: transparent;margin-left: 15%;"
                           name="password" id="password" required lay-verify="required" placeholder="请输入密码"
                            autocomplete="off" class="layui-input">
                </div>
                <!--<div class="layui-form-item" style="background: url('/static/admin/images/login/login_text.png');background-size: 100% 100%;">-->
                <!--<img alt="" src="/static/admin/images/login/login_code.png" style="float: left;margin-top: 3%;margin-left: 5%;">-->
                <!--<input type="text"  style="width: 40%;border-style: none none none none;background-color: transparent;margin-left: 6%;float: left;" name="anthcode" id="anthcode" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">-->
                <!--<img alt="刷新一下" id="authCode" src="getAuthCode.html"-->
                <!--onclick="this.src='getAuthCode.html?x='+Math.random();"-->
                <!--style="float:right;height: 38px;border-radius: 5px;">-->
                <!--</div>-->
                <div class="layui-form-item m-login-btn">
                    <div class="layui-inline" style="width: 100%;">
                        <button type="button" class="layui-btn layui-btn-normal" style="width: 100%;border-radius: 5px;"
                                lay-submit lay-filter="login">登录
                        </button>
                    </div>
                    <!--<div class="layui-inline" style="width: 100%;text-align: right;">-->
                    <!--<input name="close" checked="checked" lay-skin="switch" id="check" lay-filter="switch" lay-text="ON|OFF" type="checkbox"> <div style="font-size: 13px;float: right;margin: 10px;">记住密码</div>-->
                    <!--</div>-->
                </div>
            </form>
        </div>
    </div>
    <p style="color: #999;position: absolute;left: 45%;top: 95%;font-size: 10px;">Copyright © 2018-2019 Dioy</p>
</div>
<script src="/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    // $(function(){
    //     var href=top.location.href;
    //     var flag=href.endsWith("process/");
    //     if(!flag){
    //         if(''==''){
    //             top.location.href='http://47.94.212.7:8090/process/';
    //         }else{
    //             top.location.href='';
    //         }
    //
    //     }
    // })
    layui.use(['form', 'layedit'], function () {
        var form = layui.form,
            layer = layui.layer;

        // var ifCheck = false;
        // //记住密码
        // // 获取设置的本地存储的用户名的值
        // var loUser = localStorage.getItem('user');
        // // 获取设置的本地存储的密码的值
        // var loPass = localStorage.getItem('pass');
        // // 将本地存储的值设置给用户名和密码
        // $("#userPhone").val(loUser);
        // $("#password").val(loPass);
        // // 判断本地存储值不为空的时候将勾选的checked设置为空
        // if(loUser==''&&loPass ==''||loUser==null&&loPass ==null){
        //     $("#check").removeAttr('checked');
        //     form.render();
        // }else{
        //     ifCheck = true;
        // }
        //
        // form.on('switch(switch)', function(data){
        //     if(this.checked){
        //         ifCheck = true;
        //     }else{
        //         ifCheck = false;
        //     }
        // });

        //自定义验证规则
        // form.verify({
        //     title: function(value) {
        //         if(value.length < 5) {
        //             return '标题至少得5个字符啊';
        //         }
        //     },
        //     password: [/(.+){6,12}$/, '密码必须6到12位'],
        //     verity: [/(.+){6}$/, '验证码必须是6位'],
        //
        // });


        //监听提交
        form.on('submit(login)', function (data) {
            console.log(data.field);

            $.ajax({
                url: "/login.json",
                type: "POST",
                data: JSON.stringify(data.field),
                contentType: "application/json; text/html",
                dataType: "json",
                success: function (result) {
                    if (result.success) {
                        location.href = "/index.json";
                    } else {
                        layer.confirm(result.message,
                            {
                                icon: 2,
                                title: false,
                                btn: ['确定'],
                                area: ['100px', '120px'],
                                closeBtn: 0
                            },
                            function (index) {
                                layer.close(index);
                            });
                    }
                },
                error: function () {
                    layer.confirm('请求失败',
                        {
                            icon: 2,
                            title: false,
                            btn: ['确定'],
                            area: ['100px', '120px'],
                            closeBtn: 0
                        },
                        function (index) {
                            layer.close(index);
                        });
                }
            });

            // $.post("/control/login/doLoginForWeb.html",data.field,function(date){
            //     var obj =  eval('(' + date + ')');
            //     var flag=obj.errorCode;
            //     if(flag == 0 ){
            //         if(ifCheck){
            //             // 勾选框勾选的时候设置本地的用户名和密码的val为输入的值
            //             localStorage.setItem('user',$("#userPhone").val());
            //             localStorage.setItem('pass',$("#password").val());
            //         }else{
            //             // 勾选框未勾选的时候设置本地的用户名和密码为空
            //             localStorage.setItem("user","");
            //             localStorage.setItem("pass","");
            //         }
            //         window.location.href="/control/index.html";
            //     }else{
            //         layer.msg(obj.errorMessage);
            //         $("#authCode").attr("src","/control/login/getAuthCode.html?x="+Math.random());
            //     }
            // })
            // return false;
        });

    });
</script>
</body>
</html>